import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import LoveBox from '../views/LoveBox.vue'
import HomeAttention from '../components/HomeAttention.vue'
import HomeRecommend from '../components/HomeRecommend.vue'
import HomeNote from '../components/HomeNote.vue'
import HomeVideo from '../components/HomeVideo.vue'
import MenuNav from '../views/MenuNav.vue'
import Search from '../views/Search.vue'
import MenuDetail from '../components/MenuDetail.vue'
import NoteDetail from '../components/NoteDetail.vue'

Vue.use(VueRouter)

Vue.use(Lazyload);
Vue.use(Lazyload, {
  lazyComponent: true,
});
import { Lazyload } from 'vant';

/* const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
 if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
 return originalPush.call(this.location).catch(err => err)
} */

const routes = [
  {
    path: '/',
    // 重定向,默认显示的路由
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'Home',
    meta:{
      path: null,
    },
    redirect:  to => {
      console.log(to.meta.path);
      if(!to.meta.path){
        return "/home/homeRecommend"
      }
      else{
        return to.meta.path
      }
      // 方法接收 目标路由 作为参数
      // return 重定向的 字符串路径/路径对象
    },
    component: Home,
    children: [
      {
        path: '/home/homeAttention',
        component: HomeAttention,
        meta:{
          recommend:false,
          shouye:true,
        }
      },
      {
        path: '/home/homeRecommend',
        component: HomeRecommend,
        meta:{
          recommend:true,
          shouye:true,
        }
      },
      {
        path: '/home/homeNote',
        component: HomeNote,
        meta:{
          shouye:true,
        }
      },
      {
        path: '/home/homeVideo',
        component: HomeVideo,
        meta:{
          shouye:true,
        }
      },
    ],
  },
  {
    path: '/foodBuy',
    name: 'FoodBuy',
    component: () => import('../views/FoodBuy.vue')
  },
  {
    path: '/loveBox',
    name: 'LoveBox',
    component: LoveBox
  },
  {
    path: '/menuNav',
    name: 'MenuNav',
    component: MenuNav,
    meta:{
      noshow:true,
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: Search,
    meta:{
      noshow:true,
    }
  },
  {
    path: '/menuDetail',
    name: 'MenuDetail',
    component: MenuDetail,
    meta:{
      noshow:true,
    },
  },
  {
    path: '/noteDeatil',
    name: 'NoteDetail',
    component: NoteDetail,
    meta:{
      noshow:true,
    },
  },
]

const router = new VueRouter({
  routes
})
/* const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
} */


export default router
